package com.myself.core.controller;


import com.myself.common.page.Page
import com.myself.common.page.PageResult
import com.myself.core.entity.Record
import com.myself.core.service.RecordService
import org.springframework.web.bind.annotation.*


@RestController
@RequestMapping("/api/core")
@CrossOrigin
class CoreController(
    private val recordService: RecordService
) {

    @RequestMapping("queryAll")
    fun queryAll(@RequestBody (required = false) page: Page? ): PageResult<Record>  {
        return recordService.findAll( page ?: Page())
    }

    @PostMapping("add")
    fun addRecord(@RequestBody record: Record) {
        recordService.addOne(record)
    }

    @RequestMapping("findLast")
    fun findLastRecord() :Record? {
        return recordService.findLast()
    }
}
